<template>
  <div>
    <h3>转程航班列表</h3>
    <!--    查询条件  -->
    <el-form :inline="true" class="demo-form-inline">

      <el-form-item label="航班号">
        <el-input v-model="planeQuery.flightNumber" placeholder="仅通过航班号查询"/>
      </el-form-item>
      <el-form-item label="出发日期">
        <el-date-picker
          style="width:150px"
          v-model="planeQuery.startDateTime"
          type="date"
          placeholder="选择出发日期"
          value-format="yyyy-MM-dd HH:mm:ss"
          default-time="00:00:00"
        />

      </el-form-item>
      <!-- 出发地-->
      <el-form-item>
        <get-addr ref="addr"></get-addr>

      </el-form-item>

      <div class="buttons">

        <el-button style="margin-left: 50px" type="primary" icon="el-icon-search" @click="getList()">查 询</el-button>

        <el-button type="default" @click="resetData()">清空查询条件</el-button>
      </div>

      <br/>

    </el-form>
    <!-- 表格 -->
    <el-table
      :data="list"
      border
      fit
      highlight-current-row>

      <el-table-column align="center" label="序号" fixed="left"
                       width="70">
        <template slot-scope="scope">
          {{ (page - 1) * limit + scope.$index + 1 }}
        </template>
      </el-table-column>

      <el-table-column fixed="left" align="center" prop="flightNumber" width="100" label="第一航班"/>

      <el-table-column fixed="left" align="center" prop="secondFlightNumber" width="100" label="中转航班"/>

      <el-table-column align="center" prop="startCity" label="出发城市" width="140"/>

      <el-table-column align="center" prop="endCity" label="抵达城市" width="140"/>

      <el-table-column align="center" prop="startDateTime" label="出发日期" width="100px"/>

      <el-table-column align="center" prop="endDateTime" label="抵达日期" width="100px"/>


      <el-table-column align="center" prop="startAirport" label="出发机场" width="140px"/>

      <el-table-column align="center" prop="transitAirport" label="中转机场" width="140px"/>


      <el-table-column align="center" prop="endAirport" label="抵达机场" width="140px"/>


      <el-table-column align="center" prop="flightStartTime" label="起飞时间"/>


      <el-table-column align="center" prop="transitEndTime" label="中转降落"/>


      <el-table-column align="center" prop="transitStartTime" label="中转起飞"/>


      <el-table-column align="center" prop="grade" label="舱位等级" width="80"/>


      <el-table-column align="center" prop="seating" label="剩余票数" width="80"/>

      <el-table-column align="center" prop="price" label="票价"/>

      <el-table-column align="center" prop="flag" label="票存在？"/>


      <el-table-column align="center" prop="gmtCreate" label="创建时间" width="90"/>

      <el-table-column align="center" prop="gmtModified" label="修改时间" width="90"/>


      <el-table-column align="center" fixed="right" label="操作" width="100">

        <template slot-scope="scope">
          <router-link :to="'/plane/edit/Transfer/'+scope.row.id">

            <el-button type="primary" size="mini" icon="el-icon-edit" @click="updatePlane()">修改</el-button>
          </router-link>

          <el-button
            type="danger"
            size="mini"
            icon="el-icon-delete"
            @click="removeDataById(scope.row.id)">删除
          </el-button>
        </template>

      </el-table-column>

    </el-table>

    <!-- 分页 -->
    <el-pagination
      :current-page="page"
      :page-size="limit"
      :total="total"

      style="padding: 30px 0; text-align: center;"
      layout="total, prev, pager, next, jumper"
      @current-change="getList"
    />
  </div>

</template>
<script>
import PlaneInfo from '@/api/plane/transferInfoList'
import getAddr from "../../../components/getAddr";

export default {
  components: {
    getAddr
  },
  name: 'list',
  data() {
    return {

      list: null, // 查询之后接口返回集合
      page: 1, // 当前页
      limit: 6, // 每页显示数
      total: 0, // 总记录数
      planeQuery: {} // 条件封装对象
    }
  },
  created() {
    this.getFirstList()

  },


  methods: {

    getFirstList(page = 1) {
      this.page = page
      PlaneInfo.getPlaneList(this.page, this.limit)
        .then(response => {
          this.list = response.data.rows
          this.total = response.data.total
        })
    },
    //进入页面打开 查询出所有航班
    getList(page = 1) {
      this.page = page
      this.$refs.addr.forTransformation()
      this.planeQuery.startCity = this.$refs.addr.lastForm
      this.planeQuery.endtCity = this.$refs.addr.lastTo
      PlaneInfo.getPlaneListPage(this.page, this.limit, this.planeQuery)
        .then(response => {
          this.list = response.data.rows
          this.total = response.data.total
        })

    },

    resetData() {
      this.planeQuery = {}
      this.getFirstList()
    },

    removeDataById(id) {
      this.$confirm('此操作将永久删除讲航班记录, 是否继续?', '提示', {
        confirmButtonText: '确定',
        cancelButtonText: '取消',
        type: 'warning'
      }).then(() => {
        PlaneInfo
          .deletePlaneId(id)
          .then(response => {

            this.$message({
              type: 'success',
              message: '删除成功!'
            })
            this.getFirstList()
          })
      })
    },


    updatePlane() {
      this.$router.push({path: '/plane/save/Transfer'})

    },


  }
}
</script>


<style scoped>
.buttons {
  display: flex;
  flex-direction: row-reverse;
}
</style>
